const {
  modelNames
} = require('mongoose');

module.exports = (options) => async (req, res, next) => {
  const inflection = require('inflection')
  const modelName = inflection.classify(req.params.resource);
  // console.log ('正在访问model:', modelName);
  // console.log(require(`../../models/${modelName}`));
  // let Model = require(`../../models/${modelName}`);
  // console.log()
  // const path = require('path');
  // const Model = require(path.resolve(__dirname, `../../models/${modelName}`));
  const Model = require(`../../models/${modelName.toLowerCase()}`);
  req.Model = Model;
  next();
  // console.log(Model);
  // console.log('当前req.Model的值为', req.Model);

};